package com.aaie.gru.problemresult.service.impl;

import com.aaie.gru.problemresult.entity.GruSysProblemResult;
import com.aaie.gru.problemresult.entity.GruSysProblemResultDto;
import com.aaie.gru.problemresult.entity.GruSysProblemResultVo;
import com.aaie.gru.problemresult.mapper.GruSysProblemResultMapper;
import com.aaie.gru.problemresult.service.IGruSysProblemResultService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lvxing
 * @since 2019-08-09
 */
@Service
public class GruSysProblemResultServiceImpl extends ServiceImpl<GruSysProblemResultMapper, GruSysProblemResult> implements IGruSysProblemResultService {

    @Resource
    GruSysProblemResultMapper gruSysProblemResultMapper;

    @Override
    public IPage<GruSysProblemResultVo> selectGruSysProblemResultVoList(GruSysProblemResultDto param) {
        Page<GruSysProblemResultVo> page = new Page<>(param.getCurrent(), param.getSize());
        QueryWrapper<GruSysProblemResultVo> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param.getSearch())) {
            queryWrapper.and(qw -> qw.like("stu.user_name", param.getSearch())
                    .or().like("guar.user_name", param.getSearch()));
        }

        if(StringUtils.isNotEmpty(param.getProblemResultGuardianId())){
            queryWrapper.eq("problem_result_guardian_id",param.getProblemResultGuardianId());
        }
        queryWrapper.orderByDesc("pr.update_time_sort");
        IPage<GruSysProblemResultVo> gruSysProblemResultVoIPage = gruSysProblemResultMapper.selectGruSysProblemResultVoList(page, queryWrapper);
        return gruSysProblemResultVoIPage;
    }
}
